package force;

import java.awt.geom.Point2D;
import main.Simulation;


/**
 * This class should be extended by GlobalForces that obey an inverse power law.
 *
 * @author Paul
 * @author Lance
 *
 */
public abstract class InversePowerForce extends GlobalForce {

    /**
     * The force's scale factor.
     */
    private double myScaleFactor;

    /**
     * @param scaleFactor Force scale factor
     * @param magnitude Force magnitude
     * @param name Force name
     */
    public InversePowerForce(final double scaleFactor,
            final double magnitude, final String name) {
        super(magnitude, name);
        myScaleFactor = scaleFactor;
    }

    /**
     * Computes the inverse Force of attraction acting from p1.
     * to p2.
     *
     * @param p1 first object
     * @param p2 second object
     * @return force between the two points
     */
    public final Force computeInverseForce (Point2D p1, Point2D p2) {
        double angle = Force.angleBetween(p1, p2);
        double distance = Force.distanceBetween(p2, p1);
        double forceMagnitude = getMagnitude()
                / Math.pow(distance, myScaleFactor);
        return new Force(angle, forceMagnitude);
    }

    /**
     * @return scalefactor
     */
    public double getScaleFactor () {
        return myScaleFactor;
    }

    /**
     * @param canvas The Simulation which I want to update.
     * @param dt The time interval between updates.
     */
    public abstract void update (Simulation canvas, double dt);
}
